function checkForm(objForm) {

	var intCount = 0;
	var msgErro = "";
	var tmpMsgErro = "";
	var objErro;
	// alert ('oi');
	for (intCount = 0; intCount < objForm.elements.length; intCount++) {

		if (objForm.elements[intCount].type != null) {
			tmpMsgErro = "";
			tmpMsgErro = checkField(objForm.elements[intCount]);
			msgErro += tmpMsgErro;
			if (tmpMsgErro != "" && objErro == null && objForm.elements[intCount].type != "hidden") {
				objErro = objForm.elements[intCount];
			}

		}

	}

	if (msgErro != "") {
		msgErro = "Os seguintes erros foram encontrados :\n" + msgErro;
		alert(msgErro);
		if (objErro != null) {
			objErro.focus();
		}
		return false;
	} else {
		return true;
	}
}

function checkField(objField) {

	var objType;
	var tmpBuf = "";
	var intCount = 0;

	if (objField.fieldType == null)
		objType = objField.type;
	else
		objType = objField.fieldType;

	if (objType == "textarea" || objType == "password")
		objType = "text";

	switch (objType) {

	/***************************************************************************
	 * DEFAULT TYPES
	 **************************************************************************/
	case "text":
		var re = /\S/
		if (!re.test(objField.value))
			tmpBuf = "\n- O campo " + objField.name + " deve ser preenchido.";
		break;

	case "hidden":
		var re = /\S/
		if (!re.test(objField.value))
			tmpBuf = "\n- O campo " + objField.name + " deve ser preenchido.";
		break;

	case "select-one":
		if (objField.size > 0) {
			if (objField.selectedIndex < 0) {
				tmpBuf = "\n- O campo " + objField.name
						+ " deve ser selecionado.";
			}
		} else {
			if (objField.selectedIndex <= 0) {
				tmpBuf = "\n- O campo " + objField.name
						+ " deve ser selecionado.";
			}
		}
		break;

	case "select-multiple":
		if (objField.selectedIndex < 0) {
			tmpBuf = "\n- O campo " + objField.name + " deve ser selecionado.";
		}
		break;

	case "radio":
		var tmpChecked = false;
		var objField = eval(objField.form.name + "." + objField.name);

		try {
			if (objField.length == 1)
				tmpBuf = ""
			else {
				for (intCount = 0; intCount < objField.length; intCount++) {
					if (objField[intCount].checked) {
						tmpChecked = true;
					}
				}

				if (!tmpChecked) {
					tmpBuf = "\n- O campo " + objField[0].name
							+ " deve ser selecionado.";
				}

			}
		} catch (e) {
			if (!objField.checked) {
				tmpBuf = "\n- O campo " + objField.name
						+ " deve ser selecionado.";
			}
		}
		break;

	case "checkbox":
		var tmpChecked = false;
		var objField = eval(objField.form.name + "." + objField.name);

		try {
			if (objField.length == 1)
				tmpBuf = ""
			else {
				for (intCount = 0; intCount < objField.length; intCount++) {
					if (objField[intCount].checked) {
						tmpChecked = true;
					}
				}

				if (!tmpChecked) {
					tmpBuf = "\n- O campo " + objField[0].name
							+ " deve ser selecionado.";
				}

			}
		} catch (e) {
			if (!objField.checked) {
				tmpBuf = "\n- O campo " + objField.name
						+ " deve ser selecionado.";
			}
		}
		break;

	/***************************************************************************
	 * SPECIAL TYPES
	 **************************************************************************/
	case "password-confirm":
		var objPassword = eval(objField.form.name + "."
				+ objField.name.substr(0, objField.name.length - 8));
		if (objField.value.replace(" ", "") == "") {
			tmpBuf = "\n- O campo " + objField.name + " deve ser preenchido.";
		} else {
			if (objPassword.value != objField.value) {
				tmpBuf = "\n- Os campo " + objField.name + " e "
						+ objPassword.name + " devem ser iguais.";
			}
		}

		break;

	case "numeric":
		var re = /^[0-9]{1,}([.|,]{0,1}[0-9]{1,}){0,1}$/

		if (!re.test(objField.value)) {
			tmpBuf = "\n- O campo " + objField.name + " deve ser numérico.";
		}

		break;

	case "email":
		var re = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if (!re.test(objField.value))
			tmpBuf = "\n- O formato de " + objField.name + " não é válido.";
		break;

	case "fk":
		if (objField.value == 0 || objField.value == -1000
				|| objField.value == '') {
			tmpBuf = "\n- O campo " + objField.name + " deve ser selecionado.";
		}
		break;

	/***************************************************************************
	 * UNDEFINED TYPE
	 **************************************************************************/
	default:
		// alert( "Erro: \n'" + objField.name + "' possui um tipo inválido. \n("
		// + objType + ")" )
		break;

	}

	return tmpBuf;

}